//
//  NewsViewController.m
//  UADE-Mobile
//
//  Created by Marcos Damian Pianelli on 10/24/11.
//  Copyright (c) 2011 DG. All rights reserved.
//

#import "NewsViewController.h"
#import "TTCustomDataSource.h"
#import "TTNewsDataSource.h"

@implementation NewsViewController
@synthesize userInfo, aulaID;

/*
- (id)initWithNavigatorURL:(NSURL*)URL query:(NSString*)query {
    
    self = [super initWithNibName:@"NewsViewController" bundle:nil];
    
    if (self) {
        
        self.aulaID = query;
        
        self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(closeAction:)];
        
       
        self.variableHeightRows = TRUE;
        self.title = NSLocalizedString(@"News", @"");
        
             
    }
    
    return self;
    
}
*/


-(id)initWithID:(NSString*)IDAula{
    
    self = [super initWithNibName:@"NewsViewController" bundle:nil];
    
    if (self) {
        
        self.aulaID = IDAula;
        
     /*   self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Close", @"") style:UIBarButtonItemStyleBordered target:self action:@selector(closeAction:)];
       */ 
        
        self.variableHeightRows = TRUE;
        self.title = NSLocalizedString(@"News", @"");
        
        
    }
    
    return self;

}




-(void)didGetMoreStudentInfo:(id)model withError:(NSError*)error{
    
    self.userInfo = [(NSDictionary*)model objectForKey:@"Novedades"];
    
    
    // Do any additional setup after loading the view from its nib.
    
    
    NSMutableArray * items = [NSMutableArray array];
    
    
    for(NSDictionary * eachMessage in self.userInfo ){
        
        NSString * titulo = [NSString stringWithFormat:@"%@ // %@",[eachMessage objectForKey:@"Titulo"],[eachMessage objectForKey:@"Fecha"]];
        
        [items addObject:
         [TTTableSubtextItem itemWithText:titulo caption:[eachMessage objectForKey:@"Descripcion"]]
         ];
        
        /*    [items addObject:
         
         [TTTableMessageItem itemWithTitle:[eachMessage objectForKey:@"Titulo"] caption:[eachMessage objectForKey:@"Fecha"] text:[eachMessage objectForKey:@"Descripcion"] timestamp:nil URL:nil]
         
         ];*/
        
        
        
    }
    
    self.dataSource = [TTNewsDataSource dataSourceWithItems:items];
    
    
}




-(IBAction)closeAction:(id)sender{
    [self dismissModalViewControllerAnimated:TRUE];
}



- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [[StudentModel SharedInstance] fetchMoreInfoWithDelegate:self aulaID:self.aulaID];

}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
